package com.ruoyi.report_sj.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_sj.domain.bo.ReportSjbhwxnsyBaDetailBo;
import com.ruoyi.report_sj.domain.vo.ReportSjbhwxnsyBaDetailVo;
import com.ruoyi.report_sj.domain.ReportSjbhwxnsyBaDetail;
import com.ruoyi.report_sj.mapper.ReportSjbhwxnsyBaDetailMapper;
import com.ruoyi.report_sj.service.IReportSjbhwxnsyBaDetailService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 砂浆拌合物性能试验检测记录详情Service业务层处理
 *
 * @author zyb
 * @date 2024-05-29
 */
@RequiredArgsConstructor
@Service
public class ReportSjbhwxnsyBaDetailServiceImpl implements IReportSjbhwxnsyBaDetailService {

    private final ReportSjbhwxnsyBaDetailMapper baseMapper;

    /**
     * 查询砂浆拌合物性能试验检测记录详情
     */
    @Override
    public ReportSjbhwxnsyBaDetailVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询砂浆拌合物性能试验检测记录详情列表
     */
    @Override
    public TableDataInfo<ReportSjbhwxnsyBaDetailVo> queryPageList(ReportSjbhwxnsyBaDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportSjbhwxnsyBaDetail> lqw = buildQueryWrapper(bo);
        Page<ReportSjbhwxnsyBaDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询砂浆拌合物性能试验检测记录详情列表
     */
    @Override
    public List<ReportSjbhwxnsyBaDetailVo> queryList(ReportSjbhwxnsyBaDetailBo bo) {
        LambdaQueryWrapper<ReportSjbhwxnsyBaDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportSjbhwxnsyBaDetail> buildQueryWrapper(ReportSjbhwxnsyBaDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportSjbhwxnsyBaDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportSjbhwxnsyBaDetail::getExcelId, bo.getExcelId());
        lqw.eq(bo.getBianh() != null, ReportSjbhwxnsyBaDetail::getBianh, bo.getBianh());
        lqw.eq(bo.getShiytzl() != null, ReportSjbhwxnsyBaDetail::getShiytzl, bo.getShiytzl());
        lqw.eq(bo.getShajhsytzzl() != null, ReportSjbhwxnsyBaDetail::getShajhsytzzl, bo.getShajhsytzzl());
        lqw.eq(bo.getShiytrj() != null, ReportSjbhwxnsyBaDetail::getShiytrj, bo.getShiytrj());
        lqw.eq(bo.getBiaogmdcz() != null, ReportSjbhwxnsyBaDetail::getBiaogmdcz, bo.getBiaogmdcz());
        lqw.eq(bo.getBiaogmdczpj() != null, ReportSjbhwxnsyBaDetail::getBiaogmdczpj, bo.getBiaogmdczpj());
        lqw.eq(bo.getChadcs() != null, ReportSjbhwxnsyBaDetail::getChadcs, bo.getChadcs());
        lqw.eq(bo.getMiaobds() != null, ReportSjbhwxnsyBaDetail::getMiaobds, bo.getMiaobds());
        lqw.eq(bo.getXiacsd() != null, ReportSjbhwxnsyBaDetail::getXiacsd, bo.getXiacsd());
        lqw.eq(bo.getXiacsdpj() != null, ReportSjbhwxnsyBaDetail::getXiacsdpj, bo.getXiacsdpj());
        lqw.eq(bo.getWeizrfctqcd() != null, ReportSjbhwxnsyBaDetail::getWeizrfctqcd, bo.getWeizrfctqcd());
        lqw.eq(bo.getFenchcdsjcd() != null, ReportSjbhwxnsyBaDetail::getFenchcdsjcd, bo.getFenchcdsjcd());
        lqw.eq(bo.getFencdcz() != null, ReportSjbhwxnsyBaDetail::getFencdcz, bo.getFencdcz());
        lqw.eq(bo.getFencdczpj() != null, ReportSjbhwxnsyBaDetail::getFencdczpj, bo.getFencdczpj());
        lqw.eq(bo.getDibbtspygzsmzl() != null, ReportSjbhwxnsyBaDetail::getDibbtspygzsmzl, bo.getDibbtspygzsmzl());
        lqw.eq(bo.getLvzxsqdzl() != null, ReportSjbhwxnsyBaDetail::getLvzxsqdzl, bo.getLvzxsqdzl());
        lqw.eq(bo.getShimdbtspysjzzl() != null, ReportSjbhwxnsyBaDetail::getShimdbtspysjzzl, bo.getShimdbtspysjzzl());
        lqw.eq(bo.getLvzxshdzl() != null, ReportSjbhwxnsyBaDetail::getLvzxshdzl, bo.getLvzxshdzl());
        lqw.eq(bo.getShajybzzl() != null, ReportSjbhwxnsyBaDetail::getShajybzzl, bo.getShajybzzl());
        lqw.eq(bo.getHongghsjybzl() != null, ReportSjbhwxnsyBaDetail::getHongghsjybzl, bo.getHongghsjybzl());
        lqw.eq(bo.getHansl() != null, ReportSjbhwxnsyBaDetail::getHansl, bo.getHansl());
        lqw.eq(bo.getHanslpj() != null, ReportSjbhwxnsyBaDetail::getHanslpj, bo.getHanslpj());
        lqw.eq(bo.getBaosl() != null, ReportSjbhwxnsyBaDetail::getBaosl, bo.getBaosl());
        lqw.eq(bo.getBaoslpj() != null, ReportSjbhwxnsyBaDetail::getBaoslpj, bo.getBaoslpj());
        return lqw;
    }

    /**
     * 新增砂浆拌合物性能试验检测记录详情
     */
    @Override
    public Boolean insertByBo(ReportSjbhwxnsyBaDetailBo bo) {
        ReportSjbhwxnsyBaDetail add = BeanUtil.toBean(bo, ReportSjbhwxnsyBaDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改砂浆拌合物性能试验检测记录详情
     */
    @Override
    public Boolean updateByBo(ReportSjbhwxnsyBaDetailBo bo) {
        ReportSjbhwxnsyBaDetail update = BeanUtil.toBean(bo, ReportSjbhwxnsyBaDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportSjbhwxnsyBaDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除砂浆拌合物性能试验检测记录详情
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
